<template>
  <div class="dashboard-container">
    <div class="dashboard-text">欢迎: {{ name }}</div>

    <el-dialog title="请选择当前所属的恢复室" custom-class="tib" :visible.sync="dialogFormVisible" :show-close="false" :close-on-press-escape="false" :close-on-click-modal="false">
      <el-form :model="form"  label-position="left" label-width="100px">
        <el-form-item label="院区" >
          {{form.tBaseCourtyard}}
        </el-form-item>
        <el-form-item label="科室" >
          {{form.tBaseDepartment}}
        </el-form-item>
        <el-form-item label="恢复室" prop="areaId">
          <el-select v-model="form.id" class="filter-item" placeholder="请选择" @change="areaChange">
              <el-option v-for="item in list" :key="item.id" :label="item.configName" :value="item.id" />
          </el-select>
      </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="queding">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { mapGetters } from 'vuex'
  import {hasAll} from '../../api/admin/admin'
  import {List } from '@/api/system/apply_recover_config'
  export default {
    name: 'Dashboard',
    data() {
      return {
        dialogFormVisible:false,
        form:{
          id:null,
          name:"",
          num:"",
          tBaseCourtyard:"",
          tBaseDepartment:""
        },
        list:null,
        index:null
      }
    },
    computed: {
      ...mapGetters([
        'name'
      ])
    },
    created() {
      this.init()
    },
    methods: {

      init() {
        hasAll().then(response =>{
        
        })
        return
        let cr3 = localStorage.getItem('cr3')
        // console.log(cr3)
        let data = JSON.parse(cr3)
        let flag=''
        for(let i=0;i<data.length;i++){
          if(data[i].uri =='/nursingWorkstation'){
            for(let j=0;j<data[i].childrens.length;j++){
              if(data[i].childrens[j].uri =='task_hall'){
                flag = 'nursingWorkstation'
              }
              if(data[i].childrens[j].uri =='recovery_room_pickup'){
                flag = 'recovery_room'
              }
            }
          }
        }
        // console.log(flag)
        if(flag == 'recovery_room'){
          let recovery_room = localStorage.getItem('recovery_room')
          // console.log(recovery_room)
          if(!recovery_room){
            List().then(response => {
              let list = response.data
              const data = list
              this.list = data
              this.dialogFormVisible = true
            })
          }
        }
        
      },
      areaChange(row){
        // console.log(row)
        let index = this.list.findIndex(v => v.id == row)
        this.Index = index
        // console.log(this.list[index])
        this.form.tBaseCourtyard = this.list[index].tBaseArea.tBaseCourtyard.name
        this.form.tBaseDepartment = this.list[index].tBaseArea.tBaseDepartment.name
      },
      queding(){
        // console.log(this.list[index])
        if(this.form.id!=null){
          localStorage.setItem('recovery_room', JSON.stringify(this.list[this.Index]) )
          this.dialogFormVisible = false
        }
      }
    }
  }
</script>

<style lang="scss" scoped>
  .dashboard {
    &-container {
      margin: 30px;
    }
    &-text {
      font-size: 30px;
      line-height: 46px;
    }
  }
</style>
